<?php

include("conn.php");

$state = 2;
$errinfo = "";

$account = $_POST["account"];
$password = $_POST["password"];
$email = $_POST["email"];
$name = $_POST["name"];

$sql = "select * from user where user = '".$account."' ";
$query = mysql_query($sql);
$row = mysql_affected_rows();
if($row>0){
    $errinfo = "账号已被注册！请换个账号再次注册！";
}else{
    $sql_insert = "insert into user (user,password,name,email) values ('".$account."','".$password."','".$name."','".$email."') ";
    $query_insert = mysql_query($sql_insert);
    $row_insert = mysql_affected_rows();
    if($row_insert>0){
        $state = 1;
    }else{
        $errinfo = "注册失败";
    }
}


$resultArray = array();
$resultArray["state"] = $state; 
$resultArray["errinfo"] = $errinfo;

echo json_encode($resultArray);

?>